{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
  <h3 class="pb-3">热门搜索设置</h3>
  <table class="layui-table layui-table-form">
    <input type="hidden" value="{$id}" name="id">
    <tr>
      <td class="layui-td-gray">热门搜索</td>
      <td>
        <div class="layui-card-body" id="card-body">
          {foreach $config.hot_keyword as $k => $v }
          <div class="layui-form-item">
            <div class="layui-input-inline">
              <input type="text" name="hot_keyword[]" value="{$v}" placeholder="请输入热门搜索关键字" lay-verify="" autocomplete="off" class="layui-input">
            </div>
            <button class="layui-btn layui-btn-small layui-bg-blue add " type="button" ><i class="layui-icon"></i></button>
            {gt name="$k" value="0"}
            <button class="layui-btn layui-btn-small layui-btn-danger del" type="button" ><i class="layui-icon"></i></button>
            {/gt}
          </div>
          {/foreach}

          <!--					<div class="layui-form-item">-->
          <!--						<div class="layui-input-block">-->
          <!--							<button class="layui-btn layui-bg-blue" lay-submit lay-filter="set_hot_keyword">确认修改</button>-->
          <!--						</div>-->
          <!--					</div>-->
        </div>
      </td>
    </tr>
  </table>

  <div class="py-3">
    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  </div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
  const moduleInit = ['tool','tinymce'];
  function gouguInit() {
    var form = layui.form, tool = layui.tool;

    // 添加
    $(document).on('click','.add',function(){
      var len = $(this).parent().prevAll().length + 1;
      var str = "";
      str += "<div class='layui-form-item'>";
      str += "<div class='layui-input-inline'  >";
      str += "<input type='text' name='hot_keyword[]' value='' placeholder='请输入热门搜索关键字' lay-verify='' autocomplete='off' class='layui-input'>";
      str += "</div>";
      str += "<button class='layui-btn layui-btn-small layui-bg-blue add' type='button'><i class='layui-icon'></i></button>";
      if ( len >= 1 ) {
        str += "<button class='layui-btn layui-btn-small layui-btn-danger del' type='button' ><i class='layui-icon'></i></button>";
      }
      str += "</div>";

      $(this).parent().after(str);
    });
    $(document).on('click','.del',function(){
      var len = $(this).parent().prevAll().length + 1;
      if ( len == 1 ){
        layer.msg('不能删除');
        return;
      }
      $(this).parent().remove();
    });

    //监听提交
    form.on('submit(webform)', function (data) {

      let callback = function (e) {
        layer.msg(e.msg);
        if (e.code == 0) {
          parent.layui.tool.close(1000);
        }
      }
      tool.post("/admin/conf/edit", data.field, callback);
      return false;
    });
  }
</script>
{/block}
<!-- /脚本 -->